package main

import (
    "net/http"

    "gitee.com/shijingzhao/z-frame/core"
    "gitee.com/shijingzhao/z-frame/module"
    "gitee.com/shijingzhao/z-frame/zhttp"
    "gitee.com/shijingzhao/z-frame/zrpc"
    "gitee.com/shijingzhao/z-frame/zscript"
)

func main() {
    app := core.NewApp()

    // http
    // app.AddHttpRoutes([]zhttp.Handler{
    //     {
    //         Method:  http.MethodGet,
    //         Path:    "/api/hello1",
    //         Handler: module.Hello1Handler,
    //     },
    // })

    // 中间件
    app.AddMiddlewareHttpRoute(
        []zhttp.Middleware{
            module.Hello1HandlerMiddleware,
            module.Hello2HandlerMiddleware,
        },
        []zhttp.Route{
            zhttp.NewRoute(http.MethodGet, "/api/hello1", module.Hello1Handler),
        },
    )

    // 脚本
    app.AddScript([]zscript.Handler{
        {
            Name: "Hello1HandlerScript",
            Args: map[string]interface{}{
                "a": 1,
                "b": 2,
            },
            Author:   "sjz",
            Function: module.Hello1HandlerScript,
        },
        {
            Name: "Hello1HandlerScript",
            Args: map[string]interface{}{
                "c": 3,
                "d": 4,
            },
            Author:   "sjz",
            Function: module.Hello1HandlerScript,
        },
    })

    // rpc
    app.AddRpc([]zrpc.Handler{
        {
            Name:     "Airth",
            Obj:      new(module.Airth), // 提供rpc方法的结构
        },
    })

    // 启动
    app.Stop(func() {})
    app.Start()
}
